home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / embedded / mcu / dtmf.arc / MAKESINE.C < prev    next >
C/C++ Source or Header  |  1989-12-17  |  1KB  |  47 lines

  1. /* makesine.c - make sine wave table for assembly language */
  2.  
  3. #include        <stdio.h>
  4. #include        <math.h>
  5.  
  6. #define MAXSINE 56
  7. #define OFFSET  0
  8. #define COUNT   256
  9. #define LINECNT 8
  10. #define PI      3.14159
  11.  
  12. main (argc,argv)
  13. int argc;
  14. char **argv;
  15. {
  16.     int i,linect;
  17.     double maxsine, offset, count;
  18.  
  19.     maxsine = MAXSINE;
  20.     offset = OFFSET;
  21.     count = COUNT;
  22.     if (argc > 4) usage (argv [0]);
  23.     if (argc > 1) maxsine = atoi (argv [1]);
  24.     if (argc > 2) count = atoi (argv [2]);
  25.     if (argc == 4) offset = atoi (argv [3]);
  26.     if (maxsine == 0 || count == 0) usage (argv [0]);
  27.  
  28.     printf ("sine");
  29.     for (i = 0; i < count;)
  30.     {
  31.         printf ("\tfcb\t");
  32.         for (linect = 0;(linect < LINECNT) && (i != count); i++,linect++)
  33.             printf ("%1.0f%s",
  34.             offset + maxsine * sin (2 * PI * ((double) i / count)),
  35.             (linect == LINECNT-1) || (i == count - 1) ? "" : ",");
  36.         printf ("\n");
  37.     }
  38.     exit (0);
  39. }
  40.  
  41. usage (name)
  42. char *name;
  43. {
  44.     fprintf (stderr, "usage: %s [maxsine [count [offset]]]\n", name);
  45.     exit (1);
  46. }
  47.